/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package isd.resto.web;

import isd.resto.modelo.RT_Mozo;
import isd.resto.rn.RT_MozosRN;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 *
 * @author ctrosch
 */
@ManagedBean (name="conversoresResto")
@SessionScoped
public class ConversoresResto {
    
    @EJB private RT_MozosRN mozoRN;

    /** Creates a new instance of ConversoresBean */
    public ConversoresResto() {
        
    }

    public Converter getMozo() {
        
        return new Converter() {

            @Override
            public Object getAsObject(FacesContext context, UIComponent component, String value) {
                if (value.trim().equals("") || value == null) {
                    return null;
                }

                RT_Mozo m = mozoRN.getMozo(value);
                return m;
            }

            @Override
            public String getAsString(FacesContext context, UIComponent component, Object value) {
                if (value == null || value.equals("")) {
                    return "";
                } else {

                    return ((RT_Mozo) value).getCodigo() + "";
                }
            }
        };
    }
   
}
